package com.chinatelecom.check.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chinatelecom.check.entity.CheckTableQuestion;
import com.chinatelecom.check.model.CheckTableQuestionModel;
import com.chinatelecom.check.model.CheckTableQuestionOptionModel;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.hutool.core.bean.BeanUtil;
import com.chinatelecom.framework.model.PageData;
import com.chinatelecom.framework.model.PageParam;
import com.chinatelecom.check.entity.CheckTaskDetail;
import com.chinatelecom.check.model.CheckTaskDetailModel;
import com.chinatelecom.check.dao.CheckTaskDetailMapper;
import com.chinatelecom.check.service.CheckTaskDetailService;
import com.chinatelecom.framework.generic.GenericServiceImpl;

/**
 * CheckTaskDetail服务实现
 */
@Service
@Transactional
public class CheckTaskDetailServiceImpl extends GenericServiceImpl<CheckTaskDetail> implements CheckTaskDetailService{
	
	@Autowired
	private CheckTaskDetailMapper mapper;
	
	@Override
	public CheckTaskDetailModel getDetail(Integer id) {
		CheckTaskDetailModel model = new CheckTaskDetailModel();
		CheckTaskDetail record = mapper.selectById(id);
		BeanUtil.copyProperties(record, model);
		return model;
	}
	
	@Override
	public PageData<CheckTaskDetailModel> page(PageParam param) {
		PageData<CheckTaskDetail> data = super.getPageData(param);

		List<CheckTaskDetailModel> list = data.getList().stream().map(a -> {
			CheckTaskDetailModel dto = new CheckTaskDetailModel();
			BeanUtils.copyProperties(a, dto);
			return dto;
		}).collect(Collectors.toList());

		PageData<CheckTaskDetailModel> result = new PageData<CheckTaskDetailModel>();
		BeanUtils.copyProperties(data, result);
		result.setList(list);
		return result;
	}

	@Override
	public List<CheckTaskDetailModel> getList(Integer taskId) {
		QueryWrapper<CheckTaskDetail> q = new QueryWrapper<>();
		q.eq("TASK_ID", taskId);
		List<CheckTaskDetail> simpleList = super.getList(q);
		List<CheckTaskDetailModel> complexList = new ArrayList<>();
		for(CheckTaskDetail a: simpleList){
			CheckTaskDetailModel b = new CheckTaskDetailModel();
			BeanUtil.copyProperties(a, b);
			complexList.add(b);
		}
		return complexList;
	}


}
